
//重置树结构  路由
export const resetTree = (list, path, pid) => {
  return list && list.filter((item) =>
    pid == undefined ? item.parentId == 0 : item.parentId == pid
  ).map(e_item => {

    // if (path != null) {
    //   obj = {
    //     name: e_item.path,
    //     path: path + `/${e_item.path}`,
    //     id: e_item.id,
    //     parentId: e_item.parentId,
    //     component: e_item.path,
    //     meta: {
    //       title: e_item.title,
    //       icon: e_item.icon,
    //       type: "menu",// 类型:0:菜单;1:iframe;2:外连，3：按钮
    //       enabled: e_item.enabled,//是否启用：1启用0禁用
    //       sort: e_item.sort ? e_item.sort : 0,//排序
    //       hidden: e_item.hidden ? true : false,
    //       active: true,
    //       tagshidden: e_item.breadCrumb ? true : false
    //     }
    //   }
    //   obj.children = resetTree(list, obj.path, e_item.id)
    // } else {
    //   //path = null  path 不需要拼上级的path
    //   obj = {
    //     name: e_item.path,
    //     path: e_item.path,
    //     id: e_item.id,
    //     parentId: e_item.parentId,
    //     component: e_item.path,
    //     meta: {
    //       title: e_item.title,
    //       icon: e_item.icon,
    //       type: "menu",// 类型:0:菜单;1:iframe;2:外连，3：按钮
    //       enabled: e_item.enabled,//是否启用：1启用0禁用
    //       sort: e_item.sort ? e_item.sort : 0,//排序
    //       hidden: e_item.hidden ? true : false,
    //       active: true,
    //       tagshidden: e_item.breadCrumb ? true : false
    //     }
    //   }
    //   obj.children = resetTree(list, null, e_item.id)
    // }
    let type = null
    switch (e_item.type) {
      case 0:
        type = 'menu'
        break
      case 1:
        type = 'iframe'
        break
      case 2:
        type = 'link'
        break
      case 3:
        type = 'button'
        break
      default:
        type = 'menu'
    }

    let obj = {
      name: e_item.path,
      // path: path + `/${e_item.path}`,
      id: e_item.id,
      parentId: e_item.parentId,
      // component: ,
      component: () => import(`${e_item.path}`),
      meta: {
        title: e_item.title,
        icon: e_item.icon,
        type: type,// 类型:0:菜单;1:iframe;2:外连，3：按钮
        enabled: e_item.enabled,//是否启用：1启用0禁用
        sort: e_item.sort ? e_item.sort : 0,//排序
        // hidden: e_item.hidden == 1 ? true : false,
        hidden: e_item.hidden,
        // active: true,
        // tagshidden: e_item.breadCrumb == 1 ? true : false
      }
    }
    if (path != null) {
      obj.path = path + `/${e_item.path}`
      obj.children = resetTree(list, obj.path, e_item.id)
    } else {
      obj.path = e_item.path,
        obj.children = resetTree(list, null, e_item.id)
    }

    if (obj.children && obj.children.length > 0) {
      delete obj.component
    }
    return obj
  })
}

// 重置部门树结构
export const resetDeptTree = (list, p_id) => {
  return list && list.filter(item => p_id == undefined ? !item.pid : item.pid == p_id).map(e_item => {
    let obj = {
      id: e_item.id,
      pid: e_item.pid,
      name: e_item.name,
      label: e_item.name,
      enable: e_item.enable,
      createTime: e_item.createTime,
      updateTime: e_item.updateTime,
      remark: e_item.remark,
      children: resetDeptTree(list, e_item.id)
    }

    return obj
  })

}
